//
//  BaseMyAFN.m
//  ABookOfCartoon
//
//  Created by 于占海 on 15-5-18.
//  Copyright (c) 2015年 Power Of Ants. All rights reserved.
//

#import "BaseMyAFN.h"

@implementation BaseMyAFN


+ (void)getNetData:(NSString *)str responseGETData:(myBlock)myData
{
    AFNetworkReachabilityManager *netWorkManager = [AFNetworkReachabilityManager sharedManager];
    NSString *url_string = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    AFHTTPRequestOperationManager* manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"text/html",nil];
    [manager GET:url_string parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        [netWorkManager stopMonitoring];
        
        myData(responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        if (error != nil) {
            
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"网络不给力啊!" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
            [alertView show];
            [alertView release];
        }
        
    }];
}

+ (void)getNetData:(NSString *)str responsePOSTData:(myBlock)myData
{
    NSString *url_string = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSURL *url = [NSURL URLWithString:url_string];
    
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    [request setHTTPMethod:@"POST"];
    
    //body体
    NSDictionary *para = @{@"date":@"1427402047", @"startRecord":@"5",@"len":@"5",@"udid":@"1234567890",@"terminalType":@"Iphone",@"cid":@"215"};
    
    //[NSSet setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"text/html",nil];  代表支持所有的接口类型
    
    
    AFHTTPRequestOperationManager *netManager = [AFHTTPRequestOperationManager manager];
    netManager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"text/html",nil];
    [netManager POST:str parameters:para success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        myData(responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        NSLog(@"错误信息%@", error);
    }];
    
}

@end
